package com.echovin.esb.gateway;

import com.echovin.esb.gateway.locator.*;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
@MapperScan(basePackages= {"com.echovin.esb.gateway.mapper"})
public class GatewayApplication  implements CommandLineRunner {

	@Autowired
    GatewayRouteDefinitionLocator routeDefinitionLocator;
	@Autowired
	GatewayServiceResourceLocator serviceResourceLocator;
	@Autowired
	GatewayIPLimitResourceLocator ipLimitResourceLocator;
	@Autowired
	GatewayServiceActionResourceLocator actionResourceLocator;
	@Autowired
	GatewayParameterValidateResourceLocator validateResourceLocator;
	@Autowired
	GatewayErrorResponseLocator errorResponseLocator;

	public static void main(String[] args) {
		SpringApplication.run(GatewayApplication.class, args);
	}

	@Override
	public void run(String... strings) throws Exception {
		routeDefinitionLocator.refresh();
		serviceResourceLocator.refresh();
		ipLimitResourceLocator.refresh();
		actionResourceLocator.refresh();
		validateResourceLocator.refresh();
		errorResponseLocator.refresh();
	}

	@LoadBalanced
	@Bean
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}

}
